import akshare as ak


def get_and_save_stock_data(file_path='A股数据.xlsx'):
    try:
        # 获取A股实时行情数据
        df = ak.stock_zh_a_spot()
        # 将数据保存到Excel文件
        df.to_excel(file_path)
        print(f"成功将A股数据保存到 {file_path}")
    except Exception as e:
        print(f"获取或保存数据时出现错误: {e}")


if __name__ == "__main__":
    get_and_save_stock_data()